package com.atguigu.tingshu.account.mapper;

import com.atguigu.tingshu.model.account.UserAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

@Mapper
public interface UserAccountMapper extends BaseMapper<UserAccount> {

    /**
     * 检查与扣减
     *
     * @param userId
     * @param amount
     * @return
     */
    int checkAndLock(Long userId, BigDecimal amount);

    /**
     * 充值
     * @param userId
     * @param amount
     */
    @Update("   update user_account\n" +
            "   set total_amount = total_amount + #{amount}, available_amount = available_amount + #{amount}, total_income_amount = total_income_amount + #{amount}\n" +
            "   where user_id = #{userId}")
    Integer add(Long userId, BigDecimal amount);
}
